import { lazyReportBatch } from '../export';

/**
 * 监听 pageshow 事件
 * 页面加载完成后（包括从缓存中加载） 触发，是 load 事件的扩展
 */
const observeLoad = () => {
  window.addEventListener('pageshow', (e) => {
    requestAnimationFrame(() => {
      ['load'].forEach((type) => {
        const reportData = {
          type: 'performance',
          subType: type,
          pageUrl: window.location.href,
          startTime: performance.now() - e.timeStamp,
          title: 'pageshow事件指标',
        };
        console.log(reportData, 'reportData');
        lazyReportBatch(reportData);
      });
    });
  });
};

export default observeLoad;
